package cn.moukou.dictator.util;

import cn.moukou.dictator.pojo.ClassRoom;
import cn.moukou.dictator.pojo.Competition;
import org.neo4j.ogm.typeconversion.CompositeAttributeConverter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CompetitionConverter implements CompositeAttributeConverter<Competition> {
    @Override
    public Map<String, ?> toGraphProperties(Competition entity) {
        Map<String, Object> properties = new HashMap<>();
        if (entity != null)  {
            properties.put("competition_name", entity.getName());
            properties.put("competition_level", entity.getLevel());
            properties.put("competition_history_award_list", entity.getHistoryAwardList());
        }
        return properties;
    }

    @Override
    public Competition toEntityAttribute(Map<String, ?> map) {
        if(!map.get("node_type").toString().equals("competition")) {
            return null;
        }
        Competition entity = new Competition();
        entity.setName((String) map.get("competition_name"));
        entity.setLevel((String) map.get("competition_level"));
        entity.setHistoryAwardList((List<String>) map.get("competition_history_award_list"));

        return entity;
    }
}
